/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package anton.menu;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.sql.DataSource;

/**
 *
 * @author johan
 */
@ManagedBean(name="destroy")
@SessionScoped

public class Destroy implements Serializable{
    
      private  int  i; 
      @Resource(name="jdbc/antonsDatasource")
     
     private DataSource dataSource;
    
    
   
     public String destroy(String sql ) throws SQLException
     {
       
        
        if(dataSource==null)
            throw new SQLException("Can't get data source");// throws exception i database not available
 
        //database connection
	Connection con = dataSource.getConnection();
                 
	if(con==null)
            throw new SQLException("Can't get database connection");
        try (PreparedStatement ps = con.prepareStatement(
             sql)){
            
            
            i = ps.executeUpdate();
             
          } 
        
         con.close();     
         
     return "hello";
     } 
    
    
    
    
    
}
